import { BundleManager } from "./BundleManager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class AudioManager extends cc.Component {

    static isfontBGM: boolean = false;

    static PlayEffect(path: string) {
        BundleManager.GetBundle("AudioClips").load(path, cc.AudioClip, (err, res: cc.AudioClip) => {
            if (err) console.log(err);
            cc.audioEngine.playEffect(res, false);
        })
    }

    static PlayMusic(path: string) {
        if (path == "前半段") {
            if (!AudioManager.isfontBGM) {
                AudioManager.isfontBGM = true;
                BundleManager.GetBundle("AudioClips").load(path, cc.AudioClip, (err, res: cc.AudioClip) => {
                    if (err) console.log(err);
                    cc.audioEngine.playMusic(res, true);
                })
            }
        }
        else if (path == "后半段") {
            if (AudioManager.isfontBGM) {
                AudioManager.isfontBGM = false;
                BundleManager.GetBundle("AudioClips").load(path, cc.AudioClip, (err, res: cc.AudioClip) => {
                    if (err) console.log(err);
                    cc.audioEngine.playMusic(res, true);
                })
            }
        }
    }
}
